import customView from  './views/customer.vue'

const replaceRoutes = [
  {
    path: '/customer',
    name: 'customer',
    meta: {
      login: false // 需要登录的页面
    },
    component: customView
  }
];

const newRoutes = [
  {
    path: '/my-page',
    name: 'mypage',
    meta: {
      login: false // 需要登录的页面
    },
    component: () => import('./views/my-page.vue') // 挂载 客制化页面
  }
];

export const registerRouters = (app, Router) => {
  const routes = Router.getRoutes();
  // 替换路由
  replaceRoutes.forEach((route) => {
    const index = routes.findIndex((item) => item.path === route.path);
    console.log('replaceRoutes index: ', index);

    if (index === -1) {
      return;
    }
    route.children = routes[index].children || [];
    Router.addRoute(route);
  });

  // 添加新路由
  newRoutes.forEach((route) => {
    Router.addRoute(route.parent || 'root', route);
  });

  app.use(Router);
};
